//
//  ReviewViewController.m
//  PerfectWorld
//
//  Created by dllo on 16/9/29.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ReviewViewController.h"
#import "Masonry.h"
#import "NetworkHandler.h"
#import "NSString+LSTMD5.h"
@interface ReviewViewController ()
@property (nonatomic, strong)UITextField *textField;
@property (nonatomic, strong)UITableView *tableView;
@end

@implementation ReviewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"评论列表";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(clickReView:)];
    [self creatSubView];
}
- (void)creatSubView {
    UIView *bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = [UIColor brownColor];
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(self.view.mas_bottom);
        make.height.height.mas_equalTo(50);
        make.width.mas_equalTo(self.view.bounds.size.width);
        make.left.mas_equalTo(5);
    }];
    
    self.textField = [[UITextField alloc] init];
    [self.view addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(bottomView.mas_bottom);
        make.height.height.mas_equalTo(bottomView);
        make.width.mas_equalTo(self.view.bounds.size.width - 50);
        make.left.mas_equalTo(5);
    }];
    UIButton *btnReview = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnReview setTitle:@"发送" forState:UIControlStateNormal];
    [self.view addSubview:btnReview];
    [btnReview addTarget:self action:@selector(clickReViewBtn:) forControlEvents:UIControlEventTouchUpInside];
    [btnReview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
        make.bottom.mas_equalTo(btnReview.mas_bottom);
    }];
}
- (void)handData {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"dic"];
    NSString *secret = [dic objectForKey:@"secret"];
    NSString *key = [dic objectForKey:@"key"];
    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];
    NSString *strID = [dic objectForKey:@"id"];
    NSTimeInterval timeInterVal = [date timeIntervalSince1970];
    // 时间戳
    NSString *strTimer = [NSString stringWithFormat:@"%.0f", timeInterVal];
  NSString *str32 = [_textField.text stringWith32BitMD5Lower];
    NSString *strUrl = @"http://api.guju.com.cn/v2/strategy/commentAdd/4415";
    NSString *strBody = [NSString stringWithFormat:@"comment=%@&datestamp=%@&id=%@&key=%@&secret=%@", str32, strTimer, strID, key, secret];
    [NetworkHandler getDataByUrlString:strUrl BodyString:strBody WithDataBlock:^(id result) {
    }];
}
// 返回
- (void)clickReView:(UIBarButtonItem *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
// 发送按钮
- (void)clickReViewBtn:(UIButton *)sender {
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"dic"];
    NSDictionary *dicUser = [dic objectForKey:@"user"];
    NSString *userName = [dicUser objectForKey:@"userName"];
    if (userName.length > 0) {
        [self handData];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
